
# 账户及密码信息
account_info = [
    {'name':'wanger','passwd':123456,'balance':1000},
    {'name':'zhangsan','passwd':111111,'balance':2000},
    {'name':'lisi','passwd':222222,'balance':3000},
    {'name':'wangwu','passwd':333333,'balance':5000}
]


def login(name,passwd):
    '''
    登陆验证
    :return:
    '''

    for it_dict in range(len(account_info)):
        if name == account_info[it_dict]['name'] and passwd == account_info[it_dict]['passwd']:
            return True
    return False

def quit():
    '''
    退出系统
    :return:
    '''
    print("|==============系统已退出==============|")

def query(name): 
    '''
    查询余额
    :return:
    '''
    for it in range(len(account_info)):
        if name == account_info[it]['name']:
            money = float(account_info[it]['balance'])
            print('%s,您的余额为：%.2f元' % (name,money))

def charge(name):
    '''
    存入
    :return:
    '''
    amount_of_money = input("请输入存款金额：")
    for it in range(len(account_info)):
        if name == account_info[it]['name']:
            account_info[it]['balance'] += int(amount_of_money)
            print("存入成功，当前余额:%.2f：" % account_info[it]['balance'])

def withdraw_money(name):
    '''
    取款
    :return:
    '''
    amount_of_money = int(input("请输入取款金额："))
    for i in range(len(account_info)):
        if name == account_info[i]['name']:
            current_of_money = account_info[i]['balance']
            while amount_of_money > current_of_money:
                print("取款金额超出账户余额，请重新输入：")
                amount_of_money = int(input("请输入取款金额"))
            else:
                account_info[i]['balance'] -= amount_of_money
                print("取款成功，当前余额%.2f元" % account_info[i]['balance'])

# 系统入口
def run():
    print("|***************欢迎进入中国银行自助存取款系统***************|")

    while True:
        print("|--------------用户登陆--------------|")
        name = input("请输入用户名：")
        passwd = input("请输入密码：")
        passwd = int(passwd)

        if login(name,passwd):
            print("登陆成功")
            print("------1.存款   2.取款   3.余额查询   4.退出------")

            while True:
                cmd = input("请输入指令代码：")
                cmd = int(cmd)
                if cmd == 1:
                    charge(name)
                elif cmd == 2:
                    withdraw_money(name)
                elif cmd == 3:
                    query(name)
                elif cmd == 4:
                    quit()
                    break;
                else:
                    print("输入错误，请重新输入")
            exit()
        else:
            print("登陆失败，请重新登陆")

run()